package com.app.lxx.pregnancyberth.ui;

import static com.app.lxx.pregnancyberth.ui.VoipP2PActivity.type_load_calllogs;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.app.lxx.pregnancyberth.Mvp.Presenter.CurrencyPresenter;
import com.app.lxx.pregnancyberth.Mvp.View.CurrencyView;
import com.app.lxx.pregnancyberth.R;
import com.app.lxx.pregnancyberth.base.BaseActivity;
import com.app.lxx.pregnancyberth.base.UrlManage;
import com.app.lxx.pregnancyberth.easyphone.EasyLinphone;
import com.app.lxx.pregnancyberth.easyphone.callback.PhoneCallback;
import com.app.lxx.pregnancyberth.easyphone.callback.RegistrationCallback;
import com.app.lxx.pregnancyberth.service.DataBus;
import com.app.lxx.pregnancyberth.ui.adapter.FragmentAdapter;
import com.app.lxx.pregnancyberth.ui.entity.CallLogsEntity;
import com.app.lxx.pregnancyberth.ui.entity.MyAlbumEntity;
import com.app.lxx.pregnancyberth.ui.entity.ScreenSetData;
import com.app.lxx.pregnancyberth.ui.entity.UserInfoEntity;
import com.app.lxx.pregnancyberth.ui.fragment.MyAlbumFragment;
import com.app.lxx.pregnancyberth.utils.NetUtils;
import com.app.lxx.pregnancyberth.utils.TimeUtil;
import com.app.lxx.pregnancyberth.widge.ChineseToSpeech;
import com.app.lxx.pregnancyberth.widge.LoadDailog.LoadDialog;
import com.app.lxx.pregnancyberth.widge.UserInfo;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.google.gson.Gson;

import org.linphone.core.LinphoneCall;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Lxx on pregnancyberth
 * 2019/6/17 10:54 星期一
 * Details：我的相册
 */
public class MyAlbumActivity extends BaseActivity<CurrencyPresenter> implements CurrencyView , View.OnClickListener {

    private TextView email_ed;
    private TextView pageNum;
    private ArrayList<Fragment> fragmentList = new ArrayList<>();
    private ViewPager myViewPager;
    private List<MyAlbumEntity.DataBean> photos = new ArrayList<>();
    private ChineseToSpeech chineseToSpeech;


    private TextView targetidText;
    private View mToggleSpeaker, mToggleMute;
    private ImageView mHangUp, mCallIn;
    private boolean isUpDateStatus = true;//是否需要更新通话状态
    private boolean inComingCall = false;
    private boolean isBusy = false;  //是否正在通话中。true 表示正忙 false 表示为不忙。
    //private boolean isAnswer = false;  //是否正在通话中。true 表示正忙 false 表示为不忙。
    private boolean isCallPhone = false;
    String lastText = "";
    long lastTime = 0;
    CountDownTimer mSpeechTextTimer;

    private View  root_view, calling_view;
    private LinearLayout controlView;
    private View view_front_black;

    private ScreenSetData mScreenSetData;//??
    private long firstPressedTime = 0;



private void initSubcribes() {
    Log.e("MyAlbumActivity", "initSubcribes-shareference="+shareference);

    String bindNurseAccount = shareference.getBindNurseUser();
    if (!TextUtils.isEmpty(bindNurseAccount)) {
        phoneNumber = bindNurseAccount;
    }
    DataBus.unSubscribe("callButton");
    DataBus.unSubscribe("netChanged");
    Log.e("sssssButtonService", "VoipP2PActivity initSubcribes");


    DataBus.subscribe("callButton", new DataBus.Subscriber() {
        @Override
        protected void onReceive(DataBus.Message msg) {
            try {
                Log.e("sssssButtonService", "VoipP2PActivity onReceive msg="+msg);
                if (msg.what == 1) {//手柄监听，release版本下才能启用
                    Log.e("sssssButtonService", "VoipP2PActivity CallPhoneIntent");
                    Log.e("sssssButtonServicemsg=1", String.format("isCallPhone:%s,isBusy:%s,isAnswer:%s", isCallPhone, isBusy, "isAnswer"));

                    if (System.currentTimeMillis() - firstPressedTime > 100) {//设置按钮重复按在1秒间隔
                        if (isCallPhone) {
                            if (isBusy) {
                                // 挂断
                                calling_view.setVisibility(View.GONE);
                                hangUp();
                                isCallPhone = false;
                                isBusy = false;
                            } else {
                                // 接听
                                mCallIn.setVisibility(View.GONE);
                                calling_view.setVisibility(View.VISIBLE);
                                acceptCall();
                                isBusy = true;
                            }
                        } else {
                            try {
                                audioCall(phoneNumber);
                                isBusy=true;
                            } catch (Exception e) {
                                e.printStackTrace();
                                showToast(e.getMessage());
                            }
                        }
                    } else {
                        firstPressedTime = System.currentTimeMillis();
                    }
                    view_front_black.setVisibility(View.GONE);
                    setDelayTimeToScreen();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    DataBus.subscribe("netChanged", new DataBus.Subscriber() {
        @Override
        protected void onReceive(DataBus.Message msg) {
            try {
                boolean isConnected = NetUtils.isNetworkConnected(context);
                Log.e("NetReceiver", "网络状态：" + isConnected);
                Log.e("NetReceiver", "网络连接类型：" + NetUtils.getConnectedType(context));
                if (isConnected) {
                    try {
                        EasyLinphone.login();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}


    /**
     * 保存呼叫记录 /api/index/addcalllog
     */
    private final int index_addcalllog = 5;
    //语音呼叫//接听状态１接通２未接通3拒接4呼叫保持5取消呼叫
    public void audioCall(String dialNum) {
        isUpDateStatus = false;
        String bindNurseAccount = shareference.getBindNurseUser();
        if (!TextUtils.isEmpty(bindNurseAccount)) {
            phoneNumber = bindNurseAccount;
        }
        if (TextUtils.isEmpty(phoneNumber) || !isHavePeople) {
            showToast("未获取到责任人，请联系医护人员");
            speechText("未获取到责任人,请稍后重试，或联系医护人员");
            requestImfoIndex();
            return;
        }
//        if (isHavePeople) {
        EasyLinphone.callTo(dialNum, false);
        try {
            calling_view.setVisibility(View.VISIBLE);
            targetidText.setText("呼叫中...");
        } catch (Exception e) {
            e.printStackTrace();
        }

        String zrhs = "";//责任护士
        String zrhs_id = "";//责任护士id
        try {
            String hospital_id = maternalData.getMaternal().getHospital_id();//住院号
            String peiHuStatus = maternalData.getMaternal().getPeihu_status();//陪护状态
            String zrys = maternalData.getMaternal().getDoctor().getName();//责任医生
            zrhs = maternalData.getMaternal().getNurse().getName();
            zrhs_id = maternalData.getMaternal().getNurse().getId();
            String zchs = maternalData.getMaternal().getMidwife().getName();//助产士
        } catch (Exception e) {
            e.printStackTrace();
        }

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("maternal_id", shareference.getUserID());
        String doctor = zrhs_id;//护士id
        hashMap.put("doctor", doctor);
        hashMap.put("callname", UserInfo.UserName);
        hashMap.put("answername", zrhs);
        hashMap.put("from", shareference.getLinPhonDataZh());
        hashMap.put("to", dialNum);
        hashMap.put("call_status", "2");//未接听
        hashMap.put("calltime", TimeUtil.getTimeString());
        getP().requestGet(index_addcalllog, UrlManage.APP_URL + "index/addcalllog", hashMap);

        isCallPhone = true;
    }
    CountDownTimer loadCallLogTimer = null;

    private void stopLoadCallLogTimer() {
        if (loadCallLogTimer != null) {
            loadCallLogTimer.cancel();
        }
    }

    private void startLoadCallLogTimer() {
        CountDownTimer loadCallLogTimer = null;

        if (loadCallLogTimer != null) {
            loadCallLogTimer.cancel();
        }
        new CountDownTimer(1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                Log.d("ddd", "onTick");
            }

            @Override
            public void onFinish() {
                loadCallLogs();
            }
        }.start();
    }

    private void loadCallLogs() {
        HashMap<String, String> map = new HashMap<>();
        map.put("no", this.shareference.getLinPhonDataZh());
        map.put("call_status", "");
        getP().requestPost(type_load_calllogs, UrlManage.APP_URL + "doctor/newcalllist", map);
    }



    String phoneNumber = "";
    private boolean isHavePeople = true;
    private void requestImfoIndex() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("house_id", shareference.getUserHouseID()); //	房间id  21
        hashMap.put("bed_id", shareference.getUserBedID());//   	床位id  11

    }


    private void initView() {
        initSubcribes();
        targetidText =findViewById(R.id.targetid_text);
        mHangUp = findViewById(R.id.hang_up);
        mCallIn = findViewById(R.id.accept_call);
        mToggleSpeaker =  findViewById(R.id.toggle_speaker);
        mToggleMute =  findViewById(R.id.toggle_mute);
        calling_view =  findViewById(R.id.calling_view);

        controlView =  findViewById(R.id.intelligentControl_view);
        root_view =  findViewById(R.id.root_view);
        view_front_black =  findViewById(R.id.view_front_black);

        //设置挂断按钮
        mHangUp.setOnClickListener(MyAlbumActivity.this);
        mCallIn.setOnClickListener(MyAlbumActivity.this);
        initLinPhoneCall();
    }

    @Override
    protected void onResume() {
        super.onResume();
        isBusy = false;  //是否正在通话中。true 表示正忙 false 表示为不忙。
    }

    private void speechText(String text) {
        Log.e("speechText", "speechText:" + text);
        long time = System.currentTimeMillis();
        if (isBusy || (lastText.equals(text) && time - lastTime < 1000 * 5)) {//通话中 或者间隔不到5秒 或者重复播音  都忽略
            Log.e("speechText", "---ignore speechText:" + text);
            return;
        }
        lastTime = time;
        lastText = text;
        chineseToSpeech.speech(text);
        if (inComingCall) {
            lastText = "";
            lastTime = 0;
            isBusy = false;
            if (mSpeechTextTimer != null) {
                mSpeechTextTimer.cancel();
            }
            mSpeechTextTimer = new CountDownTimer(10 * 1000, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {

                }

                @Override
                public void onFinish() {
                    if (inComingCall) {
                        speechText("护士端呼叫...");
                    }
                }
            }.start();
        }
    }
    private void setDelayTimeToScreen() {
        try {
            long blackScreenTime = 30;//暂定单位为分钟
            if (mScreenSetData != null) {
                blackScreenTime = Long.parseLong(mScreenSetData.getData().getJg_time());
            }
            blackScreenTime = 1;//todo test
            blackScreenTime = System.currentTimeMillis() + blackScreenTime * 60 * 1000;
            view_front_black.setTag(blackScreenTime);
            LogUtils.e("current:" + TimeUtils.millis2String(System.currentTimeMillis()),
                    "close:" + TimeUtils.millis2String(blackScreenTime));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void initLinPhoneCall() {

        chineseToSpeech = new ChineseToSpeech(MyAlbumActivity.this);

        String linPhonDataIp = shareference.getLinPhonDataIp();
        String linPhonDataDq = shareference.getLinPhonDataDq();
        String linPhonDataZh = shareference.getLinPhonDataZh();
        String linPhonDataMm = shareference.getLinPhonDataMm();
        PhoneCallback phoneCallback = new PhoneCallback() {
            @Override
            public void incomingCall(LinphoneCall linphoneCall) {
                // 来电状态
                super.incomingCall(linphoneCall);
                calling_view.setVisibility(View.VISIBLE);
                EasyLinphone.toggleSpeaker(true);
                targetidText.setText("来电中...");
                inComingCall = true;
                speechText("护士端呼叫...");
                mCallIn.setVisibility(View.VISIBLE);
                mHangUp.setVisibility(View.VISIBLE);

                isCallPhone = true;
//                isAnswer = true;
                isBusy = false;
                startLoadCallLogTimer();
                //点亮屏幕
                view_front_black.setVisibility(View.GONE);
                setDelayTimeToScreen();
            }

            @Override
            public void outgoingInit(LinphoneCall linphoneCall) {
                // 呼叫初始化
                super.outgoingInit(linphoneCall);
//                    chineseToSpeech.speech("正在呼叫...");
                inComingCall = false;
                targetidText.setText("呼叫中...");
                speechText("正在呼叫...");
                mHangUp.setVisibility(View.VISIBLE);
                calling_view.setVisibility(View.VISIBLE);
                if (controlView.getVisibility() == View.VISIBLE) {
                    controlView.setVisibility(View.GONE);
                    root_view.setVisibility(View.VISIBLE);
                }

                isCallPhone = true;
//                isAnswer = false;
                isBusy = true;
                view_front_black.setVisibility(View.GONE);
                setDelayTimeToScreen();
            }

            @Override
            public void callConnected(LinphoneCall linphoneCall) {
                // 电话接通
                super.callConnected(linphoneCall);
                inComingCall = false;
                // 视频通话默认免提，语音通话默认非免提
                EasyLinphone.toggleSpeaker(EasyLinphone.getVideoEnabled());
                // 所有通话默认非静音
                EasyLinphone.toggleMicro(false);
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleSpeaker.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.VISIBLE);
                targetidText.setText("通话中...");
                speechText("已接通...");
                calling_view.setVisibility(View.VISIBLE);
                isBusy = true;
                isCallPhone = true;
            }

            @Override
            public void paused(LinphoneCall linphoneCall) {
                super.paused(linphoneCall);
                inComingCall = false;
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleSpeaker.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.VISIBLE);
                targetidText.setText("暂停通话...");
                speechText("暂停通话...");
                calling_view.setVisibility(View.VISIBLE);
                isBusy = true;
                isCallPhone = true;
            }

            @Override
            public void Resuming(LinphoneCall linphoneCall) {
                super.Resuming(linphoneCall);
                inComingCall = false;
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleSpeaker.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.VISIBLE);
                targetidText.setText("通话中...");
                speechText("恢复通话...");
                calling_view.setVisibility(View.VISIBLE);
                isBusy = true;
                isCallPhone = true;
            }

            @Override
            public void callEnd(LinphoneCall linphoneCall) {
                // 电话挂断
                super.callEnd(linphoneCall);
                inComingCall = false;
                speechText("结束通话...");
                calling_view.setVisibility(View.GONE);
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.INVISIBLE);
                mToggleSpeaker.setVisibility(View.INVISIBLE);
                targetidText.setText("结束通话...");
                Log.e("linphone", "callEnd" + linphoneCall);
                isBusy = false;
                isCallPhone = false;
                calling_view.setVisibility(View.GONE);
            }

            @Override
            public void error() {
                super.error();
                speechText("通话异常,请重试...");
                calling_view.setVisibility(View.GONE);
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.INVISIBLE);
                mToggleSpeaker.setVisibility(View.INVISIBLE);
                targetidText.setText("异常结束...");
                Log.e("linphone", "error");
                isBusy = false;
                isCallPhone = false;
            }

            @Override
            public void callReleased(LinphoneCall linphoneCall) {
                super.callReleased(linphoneCall);
                // 电话挂断
                super.callEnd(linphoneCall);
                if (isBusy) {
                    speechText("结束通话...");
                }
                calling_view.setVisibility(View.GONE);
                mCallIn.setVisibility(View.GONE);
                mHangUp.setVisibility(View.VISIBLE);
                mToggleMute.setVisibility(View.INVISIBLE);
                mToggleSpeaker.setVisibility(View.INVISIBLE);
                targetidText.setText("结束通话...");
                Log.e("linphone", "callEnd" + linphoneCall);
                isBusy = false;
                isCallPhone = false;
            }
        };
        EasyLinphone.addCallback(new RegistrationCallback() {
            @Override
            public void registrationOk() {
                super.registrationOk();
                LoadDialog.dismiss( MyAlbumActivity.this);
                showToast("登录成功！");
            }

            @Override
            public void registrationFailed() {
                LoadDialog.dismiss( MyAlbumActivity.this);
                super.registrationFailed();
                showToast("登录失败！");
            }

            @Override
            public void registrationProgress() {
                super.registrationProgress();
                LoadDialog.show( MyAlbumActivity.this, "登录中");
            }

            @Override
            public void registrationNone() {
                super.registrationNone();
            }

            @Override
            public void registrationCleared() {
                super.registrationCleared();
            }
        }, phoneCallback);

        if (TextUtils.isEmpty(linPhonDataIp) || TextUtils.isEmpty(linPhonDataDq) ||
                TextUtils.isEmpty(linPhonDataZh) || TextUtils.isEmpty(linPhonDataMm)) {
            startActivity(new Intent( MyAlbumActivity.this, ControllerActivity.class));
        } else {
            EasyLinphone.setAccount(linPhonDataZh, linPhonDataMm, linPhonDataIp + ":" + "5060");
            EasyLinphone.login();
        }
    }

    // 点击接听
    public void acceptCall() {
        changeCallStatus("1");
        EasyLinphone.acceptCall();
        isUpDateStatus = false;
    }

    // 挂断
    public void hangUp() {
        if (isUpDateStatus) {
            changeCallStatus("3");
        } else {
//            changeCallStatus("5");
        }
        EasyLinphone.hangUp();
        isBusy = false;
        isCallPhone = false;
        isUpDateStatus = true;
    }
    private String callingLogId = "";
    private final int index_change_call_status = 14;

    private void changeCallStatus(String status) {
        if (TextUtils.isEmpty(callingLogId)) {
            Log.d("callingLogId", "callingLogId:" + callingLogId);
            return;
        }
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("id", callingLogId);
        hashMap.put("call_status", status);
        getP().requestGet(index_change_call_status, UrlManage.APP_URL + "/doctor/editcall", hashMap);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.btn_closeScreen:
                //息屏
                view_front_black.setVisibility(View.VISIBLE);
                view_front_black.setTag(0);

            case R.id.accept_call:
                // 接听
                mCallIn.setVisibility(View.GONE);
                acceptCall();
                break;
            case R.id.hang_up:
                // 挂断
                calling_view.setVisibility(View.GONE);
                hangUp();
                break;

        }
    }





    @Override
    protected CurrencyPresenter createP() {
        return new CurrencyPresenter();
    }

    @Override
    protected void initBindViewId() {
        email_ed = findViewById(R.id.email_ed);
        pageNum = findViewById(R.id.pageNum);
        myViewPager = findViewById(R.id.myViewPager);
        initView();

        // chineseToSpeech = new ChineseToSpeech(context);
        myViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                pageNum.setText((i + 1) + " / " + photos.size());

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

        View email_tv = findViewById(R.id.email_tv);
        email_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submitEmail();
                //  chineseToSpeech.speech("支付宝到账 100万元");
            }
        });
        findViewById(R.id.reduce).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int currentItem = myViewPager.getCurrentItem();
                int i = --currentItem;
                if (i >= 0) {
                    myViewPager.setCurrentItem(i);
                }
            }
        });
        findViewById(R.id.plus).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int currentItem = myViewPager.getCurrentItem();
                int i = ++currentItem;
                if (i < photos.size()) {
                    myViewPager.setCurrentItem(i);
                }
            }
        });

        requestAlbumIndex();

        String email = getIntent().getStringExtra("email");
        if (!TextUtils.isEmpty(email)) {
            email_ed.setText(email);
            email_ed.setEnabled(false);
            email_tv.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected boolean hidetitle() {
        return false;
    }

    @Override
    protected String settitle() {
        return "我的相册";
    }

    @NonNull
    @Override
    public int setxmlview() {
        return R.layout.activity_my_album;
    }

    private UserInfoEntity.DataBean maternalData;

    @Override
    public void requestCurrencyView(int type, String body) {
        switch (type) {
            case 1:
                MyAlbumEntity myAlbumEntity = new Gson().fromJson(body, MyAlbumEntity.class);
                List<MyAlbumEntity.DataBean> data = myAlbumEntity.getData();
                photos.addAll(data);

                for (int i = 0; i < photos.size(); i++) {
                    MyAlbumFragment mainFragmentList = new MyAlbumFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("imgUrl", UrlManage.imageUrl +
                            photos.get(i).getAlbum_image());
                    mainFragmentList.setArguments(bundle);
                    fragmentList.add(mainFragmentList);
                }
                myViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), fragmentList));
                myViewPager.setOffscreenPageLimit(photos.size());

                if (fragmentList.size() > 0) {
                    pageNum.setText(1 + " / " + photos.size());
                }
                break;
            case type_load_calllogs:

                Log.d("ddd", body);
                CallLogsEntity logEntitys = new Gson().fromJson(body, CallLogsEntity.class);
                if (logEntitys.getCode() == 1) {
                    List<CallLogsEntity.DataBean> logs = logEntitys.getData();
                    for (CallLogsEntity.DataBean log : logs) {
                        String callstatus = log.getCall_status();
                        String id = log.getId();
                        if ("2".equals(callstatus)) {
                            if (shareference.getLinPhonDataZh().equals(log.getTo())) {
                                callingLogId = id;
                                Log.d("call", "找到id:" + callingLogId);
//                                    checkCallingStatus();
                                stopLoadCallLogTimer();
                                return;
                            }
                        }
                    }
                }
                startLoadCallLogTimer();
                break;
        }

    }

    @Override
    public void requestCurrencyViewFailed(int type, int code) {


    }

    private void requestAlbumIndex() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("maternal_id", shareference.getUserID());
        //  hashMap.put("maternal_id", "4");
        if (!utilsManage.isNull(hashMap)) {
            getP().requestGet(1, UrlManage.APP_URL + "index/album", hashMap);
        }
    }


    private void submitEmail() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("maternal_id", shareference.getUserID());
        hashMap.put("email", email_ed.getText().toString());
        if (!utilsManage.isNull(hashMap)) {
            getP().requestGet(2, UrlManage.APP_URL + "index/editinfo", hashMap);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //  chineseToSpeech.destroy();
    }
}
